/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IDSNN_1_Interface;

import IDSNN_1_Business.RedeConta;
import IDSNN_1_Data.DBConnect;
import IDSNN_1_Data.Pair;
import IDSNN_1_Data.TrainSet;
import IDSNN_1_Interface.TestInterface;
import java.util.ArrayList;
import javax.swing.JTextArea;

/**
 *
 * @author francisco
 */
public class TestInterface extends Thread{
    
    private DBConnect dbconnect;
    private TrainSet ts;
    private RedeConta rd;
    private Pair pair;
    private String path;
    private JTextArea _reportTextBox;
    private String user;
    private String pass;
    private String url;
    
    public TestInterface(JTextArea _reportTextBox, String path, String user, String pass, String url) {
        this.user=user;
        this.pass=pass;
        this.url = url;
        dbconnect = new DBConnect(pass,user, url,path);
        ts= new TrainSet(path, false);
        //"/Users/francisco/Documents/Universidade/Mestrado/2Ano/TeseMestrado/Dataset/trainSet.ts"
        rd = new RedeConta(_reportTextBox);
        this._reportTextBox = _reportTextBox;
        this.path=path;
    }
    
    public TestInterface(JTextArea _reportTextBox, RedeConta rd, String path, String user, String pass, String url){
        this._reportTextBox = _reportTextBox;
        this.rd=rd;
        this.user=user;
        this.pass=pass;
        this.url = url;
        dbconnect = new DBConnect(pass,user, url, path);
        ts= new TrainSet(path, false);
        this.path=path;
    }
    
    public void writeFile(){
        dbconnect.getArray();
    }
    
    public void trainNN(){
        ts.readTS();
        rd.trainNN(ts.getInputTest(), ts.getResultTest());
        int h=0;
    }
    
    public void execute(){
    Thread thread;
    thread = new TestInterface(_reportTextBox,rd, path,user,pass, url);
    thread.start();
    }
    
    public void run() {
    int cod;
    int attack=0;
    ArrayList<Integer> lista = new ArrayList<Integer>();
        while(true){
            cod =dbconnect.randomCod();
            if(!lista.contains(cod)){
                pair = dbconnect.getPair(cod);
                attack=rd.testNN(pair.getData(),pair.getIPS(),pair.getIPD());
                if(attack==1)
                    lista.add(cod);
            }
        }
    }
    
    public void executeIP(String ips, String ipd){
    int attack=0;
                pair = dbconnect.getPairFromIP(ips, ipd);
                attack=rd.testNN(pair.getData(),pair.getIPS(),pair.getIPD());          
    }
}
